package com.xnyzc.lhy.order.service.impl.driver;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xnyzc.lhy.common.component.redis.RedisCommon;
import com.xnyzc.lhy.common.constant.RedisPrefixConstant;
import com.xnyzc.lhy.common.entity.HeadBash64;
import com.xnyzc.lhy.common.entity.Qw;
import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.penum.driver.ESexType;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.order.common.constants.RedisKeyConstant;
import com.xnyzc.lhy.order.common.userenum.EAccountStatus;
import com.xnyzc.lhy.order.common.userenum.EBlock;
import com.xnyzc.lhy.order.common.userenum.EDriveVerfied;
import com.xnyzc.lhy.order.common.userenum.EIdentityVerfied;
import com.xnyzc.lhy.order.entity.area.OaSysArea;
import com.xnyzc.lhy.order.entity.order.OaDOrder;
import com.xnyzc.lhy.order.entity.order.OaOrderEvaluation;
import com.xnyzc.lhy.mis.entity.sidebar.OaSysOffice;
import com.xnyzc.lhy.order.entity.param.auth.SmsCode;
import com.xnyzc.lhy.order.entity.user.OaDUser;
import com.xnyzc.lhy.order.entity.user.OaDUserInfo;
import com.xnyzc.lhy.order.entity.user.OaDUserOffice;
import com.xnyzc.lhy.order.entity.vehicle.OaDDriverVehicle;
import com.xnyzc.lhy.order.entity.vehicle.OaSysVehicle;
import com.xnyzc.lhy.order.entity.work.OaDWorkRecord;
import com.xnyzc.lhy.order.feign.push.FeignMessageSendService;
import com.xnyzc.lhy.order.mapper.area.OaSysAreaMapper;
import com.xnyzc.lhy.order.mapper.order.OaDOrderMapper;
import com.xnyzc.lhy.order.mapper.order.OaOrderEvaluationMapper;
import com.xnyzc.lhy.order.mapper.sidebar.OaSysOfficeMapper;
import com.xnyzc.lhy.order.mapper.user.OaDUserInfoMapper;
import com.xnyzc.lhy.order.mapper.user.OaDUserMapper;
import com.xnyzc.lhy.order.mapper.user.OaDUserOfficeMapper;
import com.xnyzc.lhy.order.mapper.vehicle.OaDDriverVehicleMapper;
import com.xnyzc.lhy.order.mapper.vehicle.OaSysVehicleMapper;
import com.xnyzc.lhy.order.mapper.work.OaDWorkRecordMapper;
import com.xnyzc.lhy.order.service.auth.IOaAuthService;
import com.xnyzc.lhy.order.service.driver.IOaDPersonalDetailsService;
import com.xnyzc.lhy.order.service.oss.IOaFileService;
import com.xnyzc.lhy.order.service.oss.IOaOssFileClientService;
import com.xnyzc.lhy.order.service.user.IOaDUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Encoder;

import javax.management.Query;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;

/**
 * 司机个人信息
 * zhuyibin
 */
@Slf4j
@Service
public class OaDPersonalDetailsServiceImpl implements IOaDPersonalDetailsService {

    /**
     * 获取图片异常状态码
     */
    private final Integer GET_IMAGE_FILED = 111;

    /**
     * 切割用的逗号
     */
    private static final String COMMA = ",";

    @Value("${global.whitelist.oaDUserPhone}")
    private String whitelistOaDUserPhone;

    @Autowired
    private IOaAuthService iOaAuthService;
    @Autowired
    private OaDUserMapper oaDUserMapper;
    @Autowired
    private OaDUserOfficeMapper oaDUserOfficeMapper;
    @Autowired
    private OaSysOfficeMapper oaSysOfficeMapper;
    @Autowired
    private OaOrderEvaluationMapper oaOrderEvaluationMapper;
    @Autowired
    private OaDOrderMapper oaDOrderMapper;
    @Autowired
    private IOaFileService iOaFileService;
    @Autowired
    private RedisCommon redisCommon;
    @Autowired
    private FeignMessageSendService feignMessageSendService;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private IOaOssFileClientService iOaOssFileClientService;

    @Autowired
    private OaDUserInfoMapper oaDUserInfoMapper;

    @Autowired
    private OaSysAreaMapper oaSysAreaMapper;

    @Autowired
    private OaDWorkRecordMapper oaDWorkRecordMapper;

    @Autowired
    private OaDDriverVehicleMapper oaDDriverVehicleMapper;

    @Autowired
    private OaSysVehicleMapper oaSysVehicleMapper;

    @Autowired
    private IOaDUserService iOaDUserService;


    /**
     * 获取司机个人中心页面数据
     * @param driverId 司机id
     * @param userType 用户类型
     * @return
     */
    @Override
    public Map<String, Object> getPersonalDetails(Long driverId, Integer userType){
        Map<String, Object> map = new HashMap<>(16);
        OaDUser oaDUser = oaDUserMapper.selectOne(Wrappers.<OaDUser>lambdaQuery().eq(OaDUser::getDriverId, driverId));
        if (CheckUtil.objIsEmpty(oaDUser)){
            throw PangException.create(EErrorCode.tokenExpire);
        }
        map.put("driverName", CheckUtil.strIsEmpty(oaDUser.getDriverName()) ? "" : oaDUser.getDriverName());
        map.put("driverId", oaDUser.getDriverId().toString());
        map.put("driverPhone", oaDUser.getDriverPhone());
        map.put("driverSex", ESexType.findById(oaDUser.getSex()).getValue());
        map.put("department", "");
        map.put("company", "");
        map.put("star", "80");
        map.put("driverPhoto", "");
        Long avatarFileId = oaDUser.getAvatarFileId();
        if (CheckUtil.objIsNotEmpty(avatarFileId)){
            map.put("driverPhoto", iOaFileService.getFileUrl(avatarFileId));
        }
        OaDUserOffice oaDUserOffice = oaDUserOfficeMapper.selectOne(Wrappers.<OaDUserOffice>lambdaQuery().eq(OaDUserOffice::getDriverId, driverId));
        if (CheckUtil.objIsNotEmpty(oaDUserOffice)){
            OaSysOffice oaSysOffice = oaSysOfficeMapper.selectOne(Wrappers.<OaSysOffice>lambdaQuery().eq(OaSysOffice::getOfficeId, oaDUserOffice.getOfficeId()));
            if (CheckUtil.objIsNotEmpty(oaSysOffice)){
                map.put("department", oaSysOffice.getName());
                String parentIds = oaSysOffice.getParentIds();
                // 切割所有父级id
                // 遍历找公司
                if (parentIds.indexOf(COMMA) != -1){
                    String[] officeIds = parentIds.split(COMMA);
                    for (String officeId : officeIds) {
                        OaSysOffice parentOaSysOffice = oaSysOfficeMapper.selectOne(
                                Wrappers.<OaSysOffice>lambdaQuery()
                                        .eq(OaSysOffice::getOfficeId, officeId)
                        );
                        if (CheckUtil.objIsNotEmpty(parentOaSysOffice)){
                            if ("1".equals(parentOaSysOffice.getType())){
                                map.put("company", parentOaSysOffice.getName());
                                break;
                            }
                        }
                    }
                }
            }
        }
        List<OaOrderEvaluation> oaOrderEvaluations = oaOrderEvaluationMapper.selectList(
                Wrappers.<OaOrderEvaluation>lambdaQuery()
                        .eq(OaOrderEvaluation::getUserType, userType)
                        .eq(OaOrderEvaluation::getUserId, driverId)
        );
        if (!oaOrderEvaluations.isEmpty()){
            /*// 总分
            String score = "0";
            for (OaOrderEvaluation oaOrderEvaluation : oaOrderEvaluations) {
                score = CalculationUtil.add(score, EStarType.findById(oaOrderEvaluation.get).getType() + 1);
            }
            BigDecimal scoreB = new BigDecimal(score);
            BigDecimal oaOrderEvaluationsSizeB = new BigDecimal(String.valueOf(oaOrderEvaluations.size()));
            String s = scoreB.divide(oaOrderEvaluationsSizeB, 0).toString();*/
            map.put("star","4");
        }
        oaDOrderMapper.selectList(
                Wrappers.<OaDOrder>lambdaQuery()
                        .eq(OaDOrder::getDriverId, driverId)
                        .isNotNull(OaDOrder::getFinishTime)
        );
        return map;
    }

    /**
     * 司机设置个人中心获取页面数据(闪电)
     * @param driverId 司机id
     * @return
     */
    @Override
    public Map<String, Object> getPersonalDetails(Long driverId) {

        Map<String, Object> driverInfoMap = oaDUserMapper.queryDriverInfo(driverId);
        driverInfoMap.put("identityNumber", identityNumberHidden(driverInfoMap.get("identityNumber").toString()));
        if (CheckUtil.objIsEmpty(driverInfoMap.get("avatarFilePath"))) {
            driverInfoMap.put("avatarFilePath", "");
        } else {
            Rv rv = feignMessageSendService.getFileUrl((Long) driverInfoMap.get("avatarFilePath"));
            if (rv.getCode() == GET_IMAGE_FILED) {
                driverInfoMap.put("avatarFilePath", "");
            } else {
                String fileUrl = ((Map<String, String>)(rv.getData())).get("fileUrl");
                driverInfoMap.put("avatarFilePath", fileUrl);
            }
        }
        driverInfoMap.put("driverRegisterCityName","");
        String registerCityId=String.valueOf(driverInfoMap.get("registerCityId"));
        QueryWrapper<OaSysArea> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaSysArea.AD_CODE, registerCityId);
        OaSysArea area = oaSysAreaMapper.selectOne(queryWrapper);
        if(CheckUtil.objIsNotEmpty(area)){
            driverInfoMap.put("driverRegisterCityName",area.getName());
        }
        String vehNo="";
        // 司机车辆关联表
        OaDDriverVehicle oaDDriverVehicle = oaDDriverVehicleMapper.selectOne(
                Wrappers.<OaDDriverVehicle>lambdaQuery()
                        .eq(OaDDriverVehicle::getDriverId, driverId)
        );
        if(CheckUtil.objIsNotEmpty(oaDDriverVehicle)){
            OaSysVehicle oaSysVehicle = oaSysVehicleMapper.selectOne(
                    Wrappers.<OaSysVehicle>lambdaQuery()
                            .eq(OaSysVehicle::getVehicleId, oaDDriverVehicle.getVehicleId())
            );
            if(CheckUtil.objIsNotEmpty(oaSysVehicle)){
                vehNo=oaSysVehicle.getVehNo();
            }
        }
        driverInfoMap.put("vehNo",vehNo);
        // 返回类型List形式
        /*Map<String, Object> photoMap = new HashMap<>(5);
        photoMap.put("text", "头像");
        if (CheckUtil.objIsEmpty(driverInfoMap.get(OaDUser.AVATAR_FILE_ID))) {
            photoMap.put("value", "待上传");
        } else {
            Rv rv = feignMessageSendService.getFileUrl((Long) driverInfoMap.get(OaDUser.AVATAR_FILE_ID));
            if (rv.getCode() == GET_IMAGE_FILED) {
                photoMap.put("value", "");
            } else {
                String fileUrl = ((Map<String, String>)(rv.getData())).get("fileUrl");
                photoMap.put("value", fileUrl);
            }
        }
        photoMap.put("isClick",1);
        photoMap.put("param","");
        photoMap.put("isGt",1);
        arr.add(photoMap);
        Map<String, Object> nameMap = new HashMap<>(5);
        nameMap.put("text","姓名");
        nameMap.put("value",driverInfoMap.get(OaDUser.DRIVER_NAME));
        nameMap.put("isClick",0);
        nameMap.put("param","");
        nameMap.put("isGt",0);
        arr.add(nameMap);
        Map<String, Object> idMap = new HashMap<>(5);
        idMap.put("text","身份证号");
        idMap.put("value",identityNumberHidden(driverInfoMap.get(OaDUserInfo.IDENTITY_NUMBER).toString()));
        idMap.put("isClick",0);
        idMap.put("param","");
        idMap.put("isGt",0);
        arr.add(idMap);
        Map<String, Object> driveMap = new HashMap<>(5);
        driveMap.put("text","初次领取驾照日期");
        driveMap.put("value", DateUtil.convertDateToString((Date) driverInfoMap.get(OaDUserInfo.DRIVER_START_DATE)));
        driveMap.put("isClick",0);
        driveMap.put("param","");
        driveMap.put("isGt",0);
        arr.add(driveMap);
        Map<String, Object> addressMap = new HashMap<>(5);
        addressMap.put("text","城市");
        if (CheckUtil.objIsEmpty(driverInfoMap.get(OaSysArea.NAME))) {
            addressMap.put("value","未发现注册城市");
        } else {
            addressMap.put("value",driverInfoMap.get(OaSysArea.NAME));
        }
        addressMap.put("isClick",0);
        addressMap.put("param","");
        addressMap.put("isGt",0);
        arr.add(addressMap);
        Map<String, Object> identityMap = new HashMap<>(5);
        identityMap.put("text","身份证");
        identityMap.put("value","");
        identityMap.put("isClick",1);
        identityMap.put("param","1");
        identityMap.put("isGt",1);
        arr.add(identityMap);
        Map<String, Object> driveVMap = new HashMap<>(5);
        driveVMap.put("text","驾驶证");
        driveVMap.put("value","");
        driveVMap.put("isClick",1);
        driveVMap.put("param","2");
        driveVMap.put("isGt",1);
        arr.add(driveVMap);
        Map<String, Object> professionalMap = new HashMap<>(5);
        professionalMap.put("text","网约车驾驶证");
        professionalMap.put("value","");
        professionalMap.put("isClick",1);
        professionalMap.put("param","3");
        professionalMap.put("isGt",1);
        arr.add(professionalMap);
        Map<String, Object> transportMap = new HashMap<>(5);
        transportMap.put("text","网约车运输证");
        transportMap.put("value","");
        transportMap.put("isClick",1);
        transportMap.put("param","4");
        transportMap.put("isGt",1);
        arr.add(transportMap);
        System.gc();
        */

        return driverInfoMap;
    }

    /**
     * 司机个人中心获取车辆资料
     * @param driverId 司机ID
     * @return
     */
    @Override
    public Rv getCarDetails(Long driverId) {
        Map<String, Object> map = oaDUserMapper.queryCarDetails(driverId);
        if (CheckUtil.objIsEmpty(map.get("vehNo"))) {
            map.put("vehNo", "暂无车牌号信息");
        }
        if (CheckUtil.objIsEmpty(map.get("seats"))) {
            map.put("seats", "暂无车座数信息");
        } else {
            map.put("seats", map.get("seats").toString());
        }
        if (CheckUtil.objIsEmpty(map.get("color"))) {
            map.put("color", "暂无车辆颜色信息");
        }
        if (CheckUtil.objIsEmpty(map.get("carType"))) {
            map.put("carType", "暂无车型信息");
        }
        return Rv.wrap(map);
    }

    /**
     * 获取司机手机号
     * @param driverId 司机ID
     * @return
     */
    @Override
    public Rv getDriverPhone(Long driverId) {
        Map<String, Object> map = oaDUserMapper.queryDriverPhone(driverId);
        String oldPhone = map.get("driverPhone").toString();
        String phone = oldPhone.substring(0,3) + "****" + oldPhone.substring(oldPhone.length() - 4);
        map.put("driverPhone", phone);
        return Rv.wrap(map);
    }

    /**
     * 效验验证码并且修改手机号
     * @param smsCode
     * @return
     */
    @Override
    public Rv checkPhoneCode(SmsCode smsCode) {

        String tag = TokenUtil.getTag();
        Long driverId = TokenUtil.getTokenUserId();
        String userType = TokenUtil.getUserType();
        String phone = smsCode.getPhone();
        String code = smsCode.getCode();

        if (
                CheckUtil.strIsEmpty(tag) ||
                CheckUtil.objIsEmpty(driverId) ||
                CheckUtil.strIsEmpty(userType) ||
                CheckUtil.objIsEmpty(phone) ||
                CheckUtil.objIsEmpty(code)
        ) {
            throw PangException.create(EErrorCode.missingArg);
        }

        // 检查手机号是否已经注册
        QueryWrapper<OaDUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaDUser.DRIVER_PHONE, smsCode.getPhone());
        Integer phoneResult = oaDUserMapper.selectCount(queryWrapper);

        if (phoneResult > 0) {
            throw PangException.create(EErrorCode.phoneRegister);
        }

        // 检查用户
        QueryWrapper<OaDUser> oaDUserQueryWrapper = new QueryWrapper<>();
        oaDUserQueryWrapper.eq(OaDUser.DRIVER_ID, driverId);
        oaDUserQueryWrapper.select(OaDUser.VERSION, OaDUser.CODE_MONTH_COUNT,OaDUser.DRIVER_PHONE);
        OaDUser oaDUser = oaDUserMapper.selectOne(oaDUserQueryWrapper);

        if (CheckUtil.objIsEmpty(oaDUser)) {
            throw PangException.create(EErrorCode.userDetailMissingErr);
        }

        // 效验是否拥有修改手机号资格
        if (oaDUser.getCodeMonthCount() > 0) {
            throw PangException.create(EErrorCode.updatePhoneFiled);
        }

        // 检查验证码是否正确
        iOaAuthService.checkSmsCode(userType,phone,code,tag,whitelistOaDUserPhone);

        oaDUser.setDriverId(driverId);
        oaDUser.setLoginAccount(oaDUser.getDriverPhone());
        oaDUser.setDriverPhone(smsCode.getPhone());
        oaDUser.setVersion(oaDUser.getVersion());
        oaDUser.setCodeMonthCount(oaDUser.getCodeMonthCount() + 1);
        oaDUser.setUpdateUser(driverId);
        oaDUser.setUpdateTime(new Date());

        Integer result = oaDUserMapper.updateById(oaDUser);

        Map<String, Integer> map = new HashMap<>(1);
        map.put("isSuccess", result);

        return Rv.wrap(map);
    }

    /**
     * 清除每月司机可修改手机号次数
     * @return
     */
    @Override
    public void reFushUpdatePhoneCount() {

        Date now = new Date();

        QueryWrapper<OaDUser> oaDUserQueryWrapper = new QueryWrapper<>();
        oaDUserQueryWrapper.gt(OaDUser.CODE_MONTH_COUNT, 0);
        oaDUserQueryWrapper.select(OaDUser.DRIVER_ID, OaDUser.VERSION);
        List<OaDUser> oaDUsers = oaDUserMapper.selectList(oaDUserQueryWrapper);

        for (OaDUser oaDUser : oaDUsers) {
            // 重置修改次数
            oaDUser.setCodeMonthCount(0);
            // 设置基本信息
            oaDUser.setVersion(oaDUser.getVersion());
            oaDUser.setUpdateUser(oaDUser.getDriverId());
            oaDUser.setUpdateTime(now);
        }

        iOaDUserService.updateBatchById(oaDUsers);

    }

    @Override
    public Rv signOut() {
        Long driverId=TokenUtil.getTokenUserId();
        OaDUserInfo oaDUserInfo = oaDUserInfoMapper.selectOne(Qw.create().eq(OaDUserInfo.DRIVER_ID, driverId));
        if (CheckUtil.objIsEmpty(oaDUserInfo)) {
            log.info("未获取用户信息!");
            throw PangException.create(EErrorCode.userFieldError);
        }
        if (redisCommon.hashKey(String.format("%s%s", RedisPrefixConstant.WORK_OA_D_WORK_STATISTICS, TokenUtil.getTokenUserId()))) {
            throw PangException.create(EErrorCode.commutOffWork);
        }
        //您有未完成的订单
        if (CheckUtil.strIsNotEmpty(oaDUserInfo.getCurrentOrderNo())) {
            log.info("存在未完成的订单! orderNo: {}", oaDUserInfo.getCurrentOrderNo());
            throw PangException.create(EErrorCode.orderNotCompleted);
        }
        oaDUserInfo.setIsOrder(0);
        oaDUserInfo.setAcceptancOrderStatus(0);
        oaDUserInfo.setUpdateTime(new Date());
        oaDUserInfo.setUpdateUser(driverId);
        oaDUserInfoMapper.updateById(oaDUserInfo);
        Date date=new Date();
        List<OaDWorkRecord> list = oaDWorkRecordMapper.selectList(Qw.create().eq(OaDWorkRecord.DRIVER_ID, driverId).isNull(OaDWorkRecord.END_TIME));
        for (OaDWorkRecord oaDWorkRecord : list) {
            if (CheckUtil.objIsEmpty(oaDWorkRecord.getEndTime())) {
                oaDWorkRecord.setEndTime(date);
                oaDWorkRecord.setUpdateTime(date);
                oaDWorkRecord.setUpdateUser(driverId);
                oaDWorkRecord.setEndAddress("");
                oaDWorkRecord.setEndLat("");
                oaDWorkRecord.setEndLng("");
                oaDWorkRecordMapper.updateById(oaDWorkRecord);
            }
        }
        //从redis中删除key
        String key = RedisPrefixConstant.GPS_VEH_KEY_PREFIX + driverId;
        if (redisCommon.hashKey(key)) {
            redisCommon.remove(key);
        }
        return Rv.wrap(EErrorCode.success);
    }

    /**
     * 司机切换头像
     * @param file 头像文件
     * @return
     */
    @Override
    public Rv updateHead(MultipartFile file) {

        Long driverId = TokenUtil.getTokenUserId();

        // 转换成base64类型,传递文件
        String baseImg = multiPartConvertToString(file, driverId);

        HeadBash64 headBash64 = new HeadBash64();
        headBash64.setHeadImg(baseImg);

        Rv rv = iOaOssFileClientService.uploadFile(headBash64);

        QueryWrapper<OaDUser> oaDUserQueryWrapper = new QueryWrapper<>();
        oaDUserQueryWrapper.eq(OaDUser.DRIVER_ID, driverId);
        oaDUserQueryWrapper.select(OaDUser.VERSION);

        OaDUser oaDUser = oaDUserMapper.selectOne(oaDUserQueryWrapper);

        if (CheckUtil.objIsEmpty(oaDUser)) {
            throw PangException.create(EErrorCode.unData);
        }

        OaDUser updateOaDUser = new OaDUser();

        if (CheckUtil.objIsNotEmpty(rv.getData())) {
            Long fileId = (Long)((Map)rv.getData()).get("fileId");
            updateOaDUser.setAvatarFileId(fileId);
        }

        updateOaDUser.setDriverId(driverId);
        updateOaDUser.setVersion(oaDUser.getVersion());
        Integer result = oaDUserMapper.updateById(updateOaDUser);

        if (result > 0) {
            return rv;
        } else {
            throw PangException.create(EErrorCode.updateHeadFiled);
        }

    }

    private String multiPartConvertToString(MultipartFile file, Long driverId) {

        // 限制图片大小
        if (file.getSize() > 1024 * 1024) {
            throw PangException.create(EErrorCode.updateHeadLong);
        }

        BASE64Encoder encoder = new BASE64Encoder();

        String base64EncoderImg = "";

        try {
            base64EncoderImg = file.getOriginalFilename() + "," + encoder.encode(file.getBytes());
        } catch (IOException e) {
            log.error("{}", e);
            throw PangException.create(EErrorCode.updateHeadFiled);
        }

        String baseImg = base64EncoderImg.replaceAll("[\\s*\t\n\r]", "");

        return baseImg;
    }

    private final Integer SUCCESS = 1;

    /**
     * 司机状态检查
     * @return
     */
    @Override
    public Rv statusCheck() {

        Long driverId = TokenUtil.getTokenUserId();

        QueryWrapper<OaDUser> oaDUserQueryWrapper = new QueryWrapper<>();
        oaDUserQueryWrapper.eq(OaDUser.DRIVER_ID, driverId);
        oaDUserQueryWrapper.select(OaDUser.ACCOUNT_STATUS);
        OaDUser oaDUser = oaDUserMapper.selectOne(oaDUserQueryWrapper);

        if (CheckUtil.objIsEmpty(oaDUser)) {
            throw PangException.create(EErrorCode.noData);
        }

        // 成功结果
        Integer result = 0;

        List<Map<String, String>> resultMapList = new ArrayList<>();

        if (oaDUser.getAccountStatus().equals(EAccountStatus.OK.getKey())) {
            result++;
        } else {
            Map<String, String> map = new HashMap<>(1);
            map.put("errInfo", "帐号状态：" + EAccountStatus.value(oaDUser.getAccountStatus()));
            resultMapList.add(map);
        }

        Map<String, Object> resultCount = new HashMap<>(2);

        if (result.equals(SUCCESS)) {
            resultCount.put("scope", 1);
        } else {
            resultCount.put("scope", 0);
        }

        resultCount.put("errInfo", resultMapList);

        return Rv.wrap(resultCount);
    }

    /**
     * 截取前六位和后四位
     */
    private String identityNumberHidden(String identityNumber) {
        return identityNumber.substring(0,6) + "********" + identityNumber.substring(identityNumber.length()-4);
    }

}
